package movie;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {

	private String _name ;
	private Vector<Rental> _renttals = new Vector<>();
	
	public Customer (String name){
		this._name= name;
	}
	public void addRental(Rental arg){
		_renttals.addElement(arg);
	}
	public String getName (){
		return _name;
	}
	
	public String statement(){
		Enumeration<Rental> rentals = _renttals.elements();
		String result = "Rental rencord for "+getName()+"\n";
		while (rentals.hasMoreElements()) {
			Rental e =  rentals.nextElement();
			result += "\t" + e.getMovie().get_title() + "\t"+String.valueOf(e.getCharge())+"\n";
		}
		result += "Amount owed is "+String.valueOf(getTotalCharge())+"\n";
		result += "You earned "+String.valueOf(getTotalFrequentRenterPoints())+" frequent renter points";
		return result;
	}
	
	
	private double getTotalFrequentRenterPoints(){
		double result = 0;
		Enumeration<Rental> rentals = _renttals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = rentals.nextElement();
			result += rental.getFrequentRenterPoints();
		}
		return result;
	}
	
	private double getTotalCharge(){
		double result = 0;
		Enumeration<Rental> rentals = _renttals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = rentals.nextElement();
			result += rental.getCharge();
		}
		return result;
	}

}
